package com.boot.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

@Data
public class R<T> {
    private int code;
    private String message;
    private T data;

    // 新增构造函数，用于分页
    public static <T> R<IPage<T>> page(IPage<T> page) {
        R<IPage<T>> r = new R<>();
        r.code = 200;
        r.message = "操作成功";
        r.data = page;
        return r;
    }

    public static <T> R<T> success(T data) {
        R<T> r = new R<>();
        r.code = 200;
        r.message = "操作成功";
        r.data = data;
        return r;
    }

    public static <T> R<T> error(String msg) {
        R<T> r = new R<>();
        r.code = 500;
        r.message = msg;
        return r;
    }
}
